/* Konten.js */
function getQueryOK(str) {
	str = str.replace(/%3B/gi,";");
	str = str.replace(/%3F/gi,"?");
	str = str.replace(/%2F/gi,"/");
	str = str.replace(/%3A/gi,":");
	str = str.replace(/%23/gi,"#");
	str = str.replace(/%26/gi,"&");
	str = str.replace(/%3D/gi,"=");
	str = str.replace(/%2B/gi,"+");
	str = str.replace(/%24/gi,"$");
	str = str.replace(/%2C/gi,",");
	str = str.replace(/%20/gi," ");
	str = str.replace(/%25/gi,"%");
	str = str.replace(/%3C/gi,"<");
	str = str.replace(/%3E/gi,">");
	str = str.replace(/%7E/gi,"~");
	str = str.replace(/%27/gi,"'");
	str = str.replace(/~/gi,"<br/>");
	return str;
}

function getQueryValueById(id) {
	// mengembalikan nilai dari parameter query string yang dimasukkan
	var str = document.URL;
	var idx = str.indexOf(id) + id.length +1;
	var idx2 = str.indexOf("&", idx);
	if (idx2 == -1) {
		str = str.substring(idx);
	} else {
		str = str.substring(idx, idx2);
	}
	str = getQueryOK(str);
	return str;
}

function getURLQueryValueById(url,id) {
	// mengembalikan nilai dari parameter query string yang dimasukkan
	var str = url;
	var idx = str.indexOf(id) + id.length +1;
	var idx2 = str.indexOf("&", idx);
	if (idx2 == -1) {
		str = str.substring(idx);
	} else {
		str = str.substring(idx, idx2);
	}
	str = getQueryOK(str);
	return str;
}


function putPost() {
	var inputtype = getQueryValueById("inputtype");
	
	var month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
	var date = new Date();
	var h = date.getHours();
	var m = date.getMinutes();
	var d = date.getDate();
	var M = date.getMonth();
	var Y = date.getFullYear();
	//"+h+"."+m+", "+d+" " + month[M-1] + " " + Y +"
	if (inputtype == 'image') {
		document.write("<div class=\"postLike\">					<div class=\"postLikeContent\">						<a onmouseover=\"\" style=\"cursor: pointer;\" onclick=\"return likeThis('like1');\" id=\"staty\">						<img src=\"images/like.gif\" alt=\"post\" name=\"gambarLike\"/>						</a>						<div>						<span id=\"statlike1\"> </span>												</div>						<div class=\"likeCount\">							<span id=\"like1\">								<script type=\"text/javascript\">document.write(\"\"+randomXToY(-50000,50000));</script>	 								</span>						</div>						<a onmouseover=\"\" style=\"cursor: pointer;\" onclick=\"return dislikeThis('like1');\">					<img src=\"images/dislike.gif\" alt=\"post\"/>						</a>					</div>				</div>"		+ "<div class=\"postData\">				<div class=\"postTitle\">				POST1				<div class=\"postDate\">					"+h+":"+m+", "+d+" " + month[M] + " " + Y +"				</div>				</div>				<img src=\"images/logo.gif\" alt=\"post\" style=\"width : 350px;\"/>				<div class=\"postContent\">		</div>			</div>");
	} else if (inputtype == 'link') {
		document.write("<div class=\"postLike\">					<div class=\"postLikeContent\">						<a onmouseover=\"\" style=\"cursor: pointer;\" onclick=\"return likeThis('like1');\" id=\"staty\">						<img src=\"images/like.gif\" alt=\"post\" name=\"gambarLike\"/>						</a>						<div>						<span id=\"statlike1\"> </span>												</div>						<div class=\"likeCount\">							<span id=\"like1\">								<script type=\"text/javascript\">document.write(\"\"+randomXToY(-50000,50000));</script>	 								</span>						</div>						<a onmouseover=\"\" style=\"cursor: pointer;\" onclick=\"return dislikeThis('like1');\">					<img src=\"images/dislike.gif\" alt=\"post\"/>						</a>					</div>				</div>"		+"<div class=\"postData\">				<div class=\"postTitle\">				<a href = " + getQueryValueById("url") + "> "+ getQueryValueById("url")+ "</a>				<div class=\"postDate\">					"+h+":"+m+", "+d+" " + month[M] + " " + Y +"				</div>				</div>				" + getQueryValueById("deskripsi") + "				<div class=\"postContent\">				</div>			</div>");
	} else if (inputtype == 'video') {
		document.write("<div class=\"postLike\">					<div class=\"postLikeContent\">						<a onmouseover=\"\" style=\"cursor: pointer;\" onclick=\"return likeThis('like1');\" id=\"staty\">						<img src=\"images/like.gif\" alt=\"post\" name=\"gambarLike\"/>						</a>						<div>						<span id=\"statlike1\"> </span>												</div>						<div class=\"likeCount\">							<span id=\"like1\">								<script type=\"text/javascript\">document.write(\"\"+randomXToY(-50000,50000));</script>	 								</span>						</div>						<a onmouseover=\"\" style=\"cursor: pointer;\" onclick=\"return dislikeThis('like1');\">					<img src=\"images/dislike.gif\" alt=\"post\"/>						</a>					</div>				</div>"		+"<div class=\"postData\">				<div class=\"postTitle\">				<object width=\"400\" height=\"350\">		   <param name=\"movie\" value=\""+ konversiYoutubeURL(getQueryValueById("url")) +"\"></param>		   <param name=\"wmode\" value=\"transparent\"></param>		   <embed src=\""+ konversiYoutubeURL(getQueryValueById("url")) +"\" 			  wmode=\"transparent\" width=\"400\" height=\"350\"></embed>		</object>			<div class=\"postDate\">					"+h+":"+m+", "+d+" " + month[M] + " " + Y +"				</div>				</div>						<div class=\"postContent\">				</div>			</div>");
	}
}

function putComment() {
	var asal = getQueryValueById("from");
	if (asal != 'post') {
		document.write(" 			");
	}
}

function focusHandler ()
{

	textBox = document.getElementById("TextArea");
	
}

function blurHandler ()
{
	textBox = document.getElementById("TextArea");
	
}

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}



function loadHandler()
{
	var totalCount = 1;
	var rtn = getQuerystring("comment"+totalCount);	
	
	while (rtn != "")
	{
		totalCount++;
		rtn = getQuerystring("comment"+totalCount);	
	}
	
	var count = totalCount -1;
	
	while (count != 0)
	{
		rtn = getQuerystring("comment"+count);
		while (rtn.indexOf("%10") != -1 || rtn.indexOf("%20") != -1)
		{
			rtn = rtn.replace('%10','<br/>');
			rtn = rtn.replace('%20','&nbsp;');
		}
		var month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
		var date = new Date();
		var h = date.getHours();
		var m = date.getMinutes();
		var d = date.getDate();
		var M = date.getMonth();
		var Y = date.getFullYear();
		
		document.write("<div class=\"comment\"><div class=\"commentUser\"><strong><br>Angelina Jolie<br></strong></div><div class=\"commentTime\"><strong><br>"+h+":"+m+", "+d+" " + month[M] + " " + Y +"</strong></div><div class=\"commentContent\"><h5>" + rtn + "</h5></div></div>");		
		
		count--;
	}
}